﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.EquipmentManagement;
using Digitalmes.Model;

using Digitalmes.Model.EquipmentManagement;


namespace Digitalmes.ViewModel.EquipmentManagement.MaintenanceRecordVMs
{
    public partial class MaintenanceRecordPlanDetailListVM : BasePagedListVM<MaintenanceRecord, MaintenanceRecordDetailSearcher>
    {
        
        protected override List<GridAction> InitGridAction()
        {
            return new List<GridAction>
            {
            };
        }
 
        protected override IEnumerable<IGridColumn<MaintenanceRecord>> InitGridHeader()
        {
            return new List<GridColumn<MaintenanceRecord>>{
                
                this.MakeGridHeader(x => x.EquipmentId).SetEditType(EditTypeEnum.ComboBox,DC.Set<Equipment>().GetSelectListItems(Wtm, x => x.ID.ToString(),SortByName:true)).SetTitle(@Localizer["Page.关联设备"].Value),
                this.MakeGridHeader(x => x.MaintainerId).SetEditType(EditTypeEnum.ComboBox,DC.Set<FrameworkUser>().GetSelectListItems(Wtm, x => x.Name, x => x.ITCode,SortByName:true)).SetTitle(@Localizer["Page.维护人员"].Value),
                this.MakeGridHeader(x => x.MaintenanceTime).SetEditType(EditTypeEnum.Datetime).SetTitle(@Localizer["Page.维护时间"].Value),
                this.MakeGridHeader(x => x.FinishTime).SetEditType(EditTypeEnum.Datetime).SetTitle(@Localizer["Page.完成时间"].Value),
                this.MakeGridHeader(x => x.ActualHours).SetEditType(EditTypeEnum.TextBox).SetTitle(@Localizer["Page.实际工时"].Value),
                this.MakeGridHeader(x => x.Result).SetEditType(EditTypeEnum.ComboBox,typeof(MaintenanceResultEnum).ToListItems(null,true)).SetTitle(@Localizer["Page.维护结果"].Value),
                this.MakeGridHeader(x => x.Note).SetEditType(EditTypeEnum.TextBox).SetTitle(@Localizer["_Admin.Remark"].Value),

            };
        }

        
        public override IOrderedQueryable<MaintenanceRecord> GetSearchQuery()
        {
                
            var id = (long?)Searcher.PlanId.ConvertValue(typeof(long?));
            if (id == null)
                return new List<MaintenanceRecord>().AsQueryable().OrderBy(x => x.ID);
            var query = DC.Set<MaintenanceRecord>()
                .Where(x => id == x.PlanId)

                .OrderBy(x => x.ID);
            return query;
        }

    }

    public partial class MaintenanceRecordDetailSearcher : BaseSearcher
    {
        
        [Display(Name = "_Model._MaintenanceRecord._Plan")]
        public string PlanId { get; set; }
    }

}

